import Vue from 'vue'
import App from './App'
import store from './store'

import project from './pages/project/home.vue'
Vue.component('project', project)

import projectList from './pages/project/projectList.vue'
Vue.component('projectList', projectList)

import questionList from './pages/project/questionList.vue'
Vue.component('questionList', questionList)

import scoreList from './pages/project/scoreList.vue'
Vue.component('scoreList', scoreList)

import zoneList from './pages/project/zoneList.vue'
Vue.component('zoneList', zoneList)

//质量
import quality from './pages/quality/home.vue'
Vue.component('quality', quality)

import informationList from './pages/quality/informationList.vue'
Vue.component('informationList', informationList)

import matterList from './pages/quality/matterList.vue'
Vue.component('matterList', matterList)

import problemMain from './pages/problem/home.vue'
Vue.component('problemMain', problemMain)

import problemList from './pages/problem/problemList.vue'
Vue.component('problemList', problemList)

import areaList from './pages/problem/areaList.vue'
Vue.component('areaList', areaList)

// import community from './pages/community/home.vue'
// Vue.component('community',community)

import enterprise from './pages/enterprise/home.vue'
Vue.component('enterprise', enterprise)

import expert from './pages/enterprise/expert.vue'
Vue.component('expert', expert)

import recordList from './pages/enterprise/recordList.vue'
Vue.component('recordList', recordList)


import my from './pages/my/home.vue'
Vue.component('my', my)

import cuCustom from './colorui/components/cu-custom.vue'
Vue.component('cu-custom', cuCustom)



/**
 * 默认消息提醒
 */
const msg = function(title) {
	if (Boolean(title) === false) {
		return;
	}
	uni.showToast({
		title: title,
		duration: 1500,
		mask: false,
		icon: "none"
	});
}


/**
 * 判断字符是否为空
 */
const isNull = function(text) {
	if (text != null) {
		return text;
	}
	return "";
}

/**
 * 格式化时间
 */
const formatDate = function(e) {
	if (e != null) {
		e = e.replace(new RegExp(/-/gm), "/");
		var time = new Date(e);
		return time.getFullYear() + "-" + (time.getMonth() + 1) + "-" + time.getDate();
	} else {
		return '';
	}
}

/**
 * 背景颜色
 */
const bgColor = function(e) {
	var bgColor = uni.getStorageSync('bgColor') || 'white';
	if (e != null) {
		bgColor = e;
		uni.setStorage({ //缓存用户主题
			key: 'bgColor',
			data: bgColor
		})
	}
	return bgColor;
}

/**
 * 主题颜色
 */
const themeColor = function(e) {
	var themeColor = uni.getStorageSync('themeColor') || 'black';
	if (e != null) {
		themeColor = e;
		uni.setStorage({ //缓存用户主题
			key: 'themeColor',
			data: themeColor
		})
	}
	return themeColor;
}


/**
 * 网络请求
 * @param {Object} url
 * @param {Object} data
 */
const request = async function(url, data, method) {
	let token = uni.getStorageSync('token') || '';

	let promise = new Promise((resolve, reject) => {
		uni.request({
			url: this.$api + url,
			data: data,
			method: method,
			header: method.toUpperCase == 'GET' ? {
				// GET请求
				'Authorization': token,
				'X-Requested-With': 'XMLHttpRequest',
				"Accept": "application/json",
				"Content-Type": "application/json; charset=UTF-8"
			} : {
				'Authorization': token,
				'X-Requested-With': 'XMLHttpRequest',
				'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
			}
		}).then((res) => {
			resolve(res[1])
		}).catch((response) => {
			reject(response)
		})
	})

	return promise;
}

const httpGet = function(url, data) {
	return this.$request(url, data, 'GET');
}
const httpPost = function(url, data) {
	return this.$request(url, data, 'POST');
}
const dateFormat = function(now) {
	var year = now.getFullYear();
	var month = now.getMonth() + 1;
	var date = now.getDate();
	var hour = now.getHours();
	var minute = now.getMinutes();
	var second = now.getSeconds();
	return year + "-" + month + "-" + date;
}


Vue.config.productionTip = false
// Vue.prototype.$api = "/api"; //H5环境
Vue.prototype.$api = "http://14.29.131.57:8081";// 打包App环境
// Vue.prototype.$api = "http://2979ik6133.zicp.vip";// 本地App环境
Vue.prototype.$store = store;
Vue.prototype.$msg = msg;
Vue.prototype.$isNull = isNull;
Vue.prototype.$formatDate = formatDate;
Vue.prototype.$themeColor = themeColor;
Vue.prototype.$bgColor = bgColor;
Vue.prototype.$request = request;
Vue.prototype.$httpGet = httpGet;
Vue.prototype.$httpPost = httpPost;
Vue.prototype.$dateFormat = dateFormat;

App.mpType = 'app'

const app = new Vue({
	...App
})
app.$mount()
